<template>
  <div id='views'>
    <div class="content">
      <router-link to="/edit_pws">
        <span>修改登录密码</span>
        <img src="../../common/imgs/arrowright.png" alt="" class="right">
      </router-link>
      <router-link :to="{path:'/transaction_password',query:{setPws:hasPws}}" v-if='hasPws === true'>
        <span>交易密码</span>
        <img src="../../common/imgs/arrowright.png" alt="" class="right">
        <span class="rightTxt">已设置</span>
      </router-link>
      <router-link :to="{path:'/transaction_password',query:{setPws:hasPws}}" v-if='hasPws === false'>
        <span>交易密码</span>
        <img src="../../common/imgs/arrowright.png" alt="" class="right">
        <span class="rightTxt">未设置</span>
      </router-link>
      <a href="javascript:;" @click='relname'>
        <span>实名认证</span>
        <img src="../../common/imgs/arrowright.png" alt="" class="right">
        <span class="rightTxt pass" v-if='relNamePass === 1'>已通过</span>
        <span class="rightTxt pass" v-if='relNamePass === 0'>未通过</span>
        <span class="rightTxt pass" v-if='relNamePass === -1'>审核中</span>
        <span class="rightTxt pass" v-if='relNamePass === 2'>未实名</span>
        <img src="../../common/imgs/pass.png" alt="" class="passimg" v-if='relNamePass === 1'>
        <img src="../../common/imgs/inpass.png" alt="" class="passimg" v-if='relNamePass === -1'>
        <img src="../../common/imgs/notpass.png" alt="" class="passimg" v-if='relNamePass === 0'>
      </a>
      <p id='login_out'>
        <a href="javascript:void 0;" class="yellowbtn" @click='login_out'>退出登录</a>
      </p>
    </div>
  </div>
</template>

<script>
  import {postLogout, isRelNameVerify, isSetTransactionPws, ifNeedRechargeVerfy} from '../../http/api';
  import store from '../../store/store';
  export default {
    name: 'setting',
    data () {
      return {
        introduce : '设置',
        hasPws : 'false',//是否设置交易密码
        relNameData : '',//实名认证信息
        verFyCode : '',//充值校验信息
        userName : '',//用户真实姓名
        userIdCard : '',//用户身份证号
        relNamePass : '',//实名认证:0 未通过， 1 已通过， -1 审核中  2未实名审核
      }
    },
    mounted(){
      let thiz = this;
      this.loading(true);
      let Not = { noToast:true, noLoading:true }; //禁止使用ajax默认提示，loading
      let https = [
        ifNeedRechargeVerfy(Not).then(res => {
          thiz.verFyCode = Number(res.data) || 2; //是否充值校验的类型 // 1已实名 ， 3新手未下单，弹窗提示实名(不用必须去实名)   2未实名（必须实名）
        }),
        isRelNameVerify(Not).then( res => {
            let code = Number( res.code );
            thiz.relNameData = res.data;
            switch(code){
               case 609:
                 thiz.relNamePass = 2 ; break;
               case 602:
                 thiz.relNamePass = -1 ; break;
               case 614:
                 thiz.relNamePass = 0 ; break;
               case 200:
                 let data = res.data;
                 thiz.relNamePass = Number(data.status);
                 thiz.userName = data.name;
                 thiz.userIdCard = data.id_num;
                 break;
            }
        }),
        isSetTransactionPws(Not).then( res => {
          thiz.hasPws = Number(res.code) == 344 ? false : true;
        })
      ];
      Promise.all( https ).then( res => {
        thiz.closeLoading();
      })
    },
    methods:{
      relname(){
        let thiz = this , relNamePass = this.relNamePass;
        let sendData = JSON.stringify(thiz.relNameData);
        switch (relNamePass) {
          case 2 :
            if(thiz.verFyCode === 1){
              let query = { rechargeVerify : false };
              if( thiz.userName ){
                query.userIdCard = thiz.userIdCard;
                query.userName  = thiz.userName;
              }
              thiz.$router.push({path: '/china_verification' , query : query});
            }else{
              thiz.$router.push({path: '/chose_foreign'});
            }
            break;
          case -1:
            thiz.$router.push({path:'/audit_in',query:{ data : sendData}} );
            break;
          case 1:
            thiz.$router.push({path:'/audit_pass',query:{ data : sendData}} );
            break;
          case 0:
            thiz.$router.push({path:'/audit_notpass',query:{ data : sendData}} );
            break;
        }
      },
      login_out(){
        /*退出登录*/
        postLogout({noToast:true}).then(res => {
          if( res.code == 200 ){
            let toast = require('../../common/js/toast').toast;
            toast('请重新登陆');
            this.$store.commit('storageRemove','all');
            this.$router.replace({path: '/login'})
          }
        });
      }

    }
  }
</script>

<style type="text/less" lang='less' scoped>
  #views{
    padding:0.41rem 0.3rem;background: #F8F8F8;
    .content{
      background: #fff;border-radius: 0.04rem;padding-left: 0.36rem;padding-right: 0.36rem;;
      >a{
        display: inline-block;width:100%;padding: 0.36rem 0;font-size: 0.28rem;text-align: left;line-height: 0.34rem;border-bottom: 0.01rem solid#E5E5E5;
        .right{
          float: right;height:0.25rem;margin-top: 0.03rem;
        }
        .rightTxt{
          float: right;color:#777D84;font-size: 0.28rem;padding-right: 0.2rem;line-height: 0.34rem;;
         }
         .passimg{
           height:0.34rem;float: right;margin-right: 0.12rem;;
         }
      }
      #login_out{
        padding: 0.36rem 0;
        a{
          display: inline-block;width:100%;line-height: 0.88rem;font-size: 0.3rem;margin: 0;
        }
      }
    }

  }
</style>
